package com.xyw.his00.service.Impl.dbImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.xyw.his00.dto.OrderDTO;
import com.xyw.his00.mapper.RegisterMapper;
import com.xyw.his00.pojo.dbpojo.Register;
import com.xyw.his00.service.dbservice.RegisterService;
import com.xyw.his00.utils.NumberUtils.RandomUtil;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class RegisterServiceImpl extends ServiceImpl<RegisterMapper, Register> implements RegisterService {
    @Resource
    private RegisterMapper registerMapper;
    @Resource
    private RedisTemplate<String,Object> redisTemplate;
    //病历号
    @Override
    public String register(int caseNumber) {
        //生成病历号
        return RandomUtil.getRandomOrderNo()+caseNumber;
    }

    @Override
    public List<OrderDTO> getOrderDTO(int id) {
     Object value=redisTemplate.opsForValue().get(String.valueOf(id));
     if(value==null){
         List<OrderDTO> list= registerMapper.getOrderDTO(id);
         redisTemplate.opsForValue().set(String.valueOf(id),list);
         return list;
     }else{
         List<OrderDTO> orderDTOs = registerMapper.getOrderDTO(id);
         redisTemplate.opsForValue().set(String.valueOf(id),orderDTOs);
         return orderDTOs != null ? orderDTOs : Collections.emptyList(); // 如果未找到，返回空列表
     }
    }
}
